package user;

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import javax.ejb.SessionContext;

import descriptor.UserDescriptor;
import extras.Md5Encryption;

/**
 * UserBean
 * 
 * @author Mamadou TOURE
 * 
 * The UserBean class implements all the methods that a remote client expect to find
 * when it calls the interface (User).
 * 
 * Note : 	-It extends the EntityBean class.
 */
public abstract class UserBean implements EntityBean 
{

	//	 persistent fields
	/** 
	 * getId
	 * 
	 * The getId abstract method returns a integer which indicates diary's identification number of a user.
	 * 
	 * @return		The diary's identification number of a user.
	 */
	public abstract int getId();
	
	/** 
	 * setId
	 * 
	 * The setId abstract method sets the diary's identification number.
	 * 
	 * @param id		The new diary's identification number that we want to add.
	 */
	public abstract void setId(int id);
	
	/** 
	 * getFirstname
	 * 
	 * The getFirstname abstract method returns a string which indicates the firstname of a user.
	 * 
	 * @return		The user's firstname.
	 */
	public abstract String getFirstName();
	
	/** 
	 * setFirstname
	 * 
	 * The setFirstname abstract method sets the firstname of a user.
	 * 
	 * @param firstname		The firstname that we want to add.
	 */
	public abstract void setFirstName(String firstName);
	
	/** 
	 * getSurname
	 * 
	 * The getSurname abstract method returns a string which indicates the surname of a user.
	 * 
	 * @return		The user's surname.
	 */
	public abstract String getName();
	
	/** 
	 * setSurname
	 * 
	 * The setSurname abstract method sets the surname of a user.
	 * 
	 * @param surname		The surname that we want to add.
	 */
	public abstract void setName(String name);
	
	/** 
	 * getLogin
	 * 
	 * The getLogin abstract method returns a string which indicates the login name that user have to provide to log into the application.
	 * 
	 * @return		The login name to provide by the user.
	 */
	public abstract String getLogin();
	
	/** 
	 * setLogin
	 * 
	 * The setLogin abstract method sets the login name of a user.
	 * 
	 * @param login		The new login name that we want to add.
	 */
	public abstract void setLogin(String login);
	
	/** 
	 * getPassword
	 * 
	 * The getPassword abstract method returns a string which indicates the password that user have to provide to log into the application.
	 * 
	 * @return		The password to provide by the user.
	 */
	public abstract String getPasswd();
	
	/** 
	 * setPassword
	 * 
	 * The setPassword abstract method sets the password of a user.
	 * 
	 * @param password		The new password that we want to add.
	 */
	public abstract void setPasswd(String passwd);
	
	/** 
	 * getEmail
	 * 
	 * The getEmail abstract method returns a string which indicates the email address of a user.
	 * 
	 * @return		The email address of a user.
	 */
	public abstract String getMail();
	
	/** 
	 * setEmail
	 * 
	 * The setEmail abstract method sets the email address of a user.
	 * 
	 * @param mail		The new email address that we want to add.
	 */
	public abstract void setMail(String mail);
	
	/** 
	 * getType
	 * 
	 * The getType abstract method returns an integer which indicates the type of a user.
	 * ie STUDENT = 1, ADMIN = 2, COMPSUP = 3, ...
	 * 
	 * @return		The type of a user.
	 */
	public abstract int getType();
	
	/** 
	 * setType
	 * 
	 * The setType abstract method sets the type of a user.
	 * 
	 * @param type		The new user's type.
	 */
	public abstract void setType(int type);
	
	/** 
	 * ejbCreate
	 * 
	 * The ejbCreate method defines the operations to follow to create an EJB.
	 * This method refers to the method create in the remote interface.
	 * 
	 * @param firstName			User's firstname.
	 * @param name				User's surname.
	 * @param login				User's login name.
	 * @param passwd			User's password.
	 * @param mail				User's email address.
	 * 
	 * @return 					Return's values is always null.
	 */
	public String ejbCreate(String firstName, String name, String login, String passwd,  String email) throws CreateException
	{
		setFirstName(firstName);
		setName(name);
		setLogin(login);
		setPasswd(Md5Encryption.getEncodedPassword(passwd));
		setMail(email);
		setType(0);
		return null;
	}
	
	/** 
	 * getDescriptor
	 * 
	 * The getDescriptor method provides a Java object instead of a bean object. Hence, the object is directly accessible from a servlet or a JSP.
	 * 
	 * @param getId()					The ID of the student
	 * @param getFirstName()			The user's firstname
	 * @param getName()					The user's surname
	 * @param getLogin()				The user's login
	 * @param getPasswd()				The user's password
	 * @param getMail()					The user's email address
	 * @param getType()					The user's type (eg 1= user of type Student,.....)
	 * 
	 * @return 							A UserDescriptor's object.
	 */
	public UserDescriptor getDescriptor()
	{
		return new UserDescriptor(getId(),getFirstName(),getName(),getLogin(),getPasswd(),getMail(),getType());
	}
	
	public void ejbPostCreate(String firstName, String name, String login, String passwd,  String email) throws CreateException{}
	public void ejbActivate() throws EJBException, RemoteException {}
	public void ejbPassivate() throws EJBException, RemoteException {}
	public void ejbRemove() throws EJBException, RemoteException, RemoveException{}
	public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {}
	public void ejbLoad() throws EJBException, RemoteException {}
	public void ejbStore() throws EJBException, RemoteException {}
	public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException {}
	public void unsetEntityContext() throws EJBException, RemoteException {}

}
